import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;


public class IOTrasportServer {
	public static void main(String[] args) throws IOException, InterruptedException {
		ServerSocket s = new ServerSocket(90);
		Socket clientSocket = s.accept();
		System.out.println("Client was accepted");
		PrintWriter outFile = new PrintWriter(new OutputStreamWriter(new FileOutputStream(args[0])), true);
		BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
		PrintWriter out = new PrintWriter(new OutputStreamWriter((clientSocket.getOutputStream())), true);
		String input;
		do {
			input = in.readLine();
			outFile.println(input);
		} while (!(input.equals("end")));
		outFile.close();
		out.write("That's all, thank you!");
		out.close();
		s.close();
	}
}
